const { parse, tokenizer } = require('./parser.js')
const { log, ensure, equals } = require('./utils.js')

const testParse = () => {
    let s1 = String.raw `{
    "s1": "gua",
    "num1": 11,
    "num2": -20,
    "num3": 12.5
}`

    let r1 = parse(s1)
    ensure(r1.num2 === -20 && r1.num3 === 12.5, 'test parse 1')

    let s2 = String.raw `{
    "s1": "gua",
    "s2": "a\bb\fc\nd\re\tf\\g\/h\"i"
}`
    let r2 = parse(s2)
    ensure(r2.s2 === "a\bb\fc\nd\re\tf\\g\/h\"i", 'test parse 2')

    let s3 = String.raw `{
    "a1": [1, "2", -3, 4.5]
}`
    let r3 = parse(s3)
    ensure(r3.a1.length === 4 && r3.a1.includes(4.5), 'test parse 3')

    let s4 = String.raw `{
    "obj": {
        "k1": "v1",
        "k2": "v2"
    }
}`
    let r4 = parse(s4)
    ensure(Object.keys(r4.obj).length === 2 && r4.obj.k2 === 'v2', 'test parse 4')


    let s5 = String.raw `{
    "a1": [1, "2", -3, 4.5, {
        "k0": "v0"
    }],
    "obj": {
        "k1": "v1",
        "k2": ["10", -20]
    }
}`
    let r5 = parse(s5)
    ensure(r5.a1.length === 5 && r5.obj.k2[1] === -20, 'test parse 5')

    let s6 = String.raw `[
    true, "true"
]`
    let r6 = parse(s6)
    ensure(r6.length === 2 && String(r6[0]) === r6[1], 'test parse 6')

    let s7 = String.raw `[
    true, null, {
        "obj": {
            "k1": "v1"
        }
    }
]`
    let r7 = parse(s7)
    ensure(r7.length === 3 && r7[2].obj.k1 === 'v1', 'test parse 7')

    let s8 = String.raw `[
    true, null, {
        "obj": {
            "k1": "v1"
        }
    }, [1, "2", -3, 4.5]
]`
    let r8 = parse(s8)
    ensure(r8[3].length === 4 && r8[3][2] === -3, 'test parse 8')

    let s9 = String.raw `[
    true, null, {
        "obj": {
            "k1": "v1",
            "k2": [10, "-20"]
        }
    }, [1, "2", {
        "a1": {
            "k3": "v3"
        }
    }]
]`
    let r9 = parse(s9)
    ensure(r9[2].obj.k2.length === 2 && r9[3][2].a1.k3 === 'v3', 'test parse 9')
}

const __main = () => {
    testParse()
}

__main()